functor
export
   Longitud
   Tomar
   Eliminar
   Agregar
   Miembro
   Posicion
define
   fun {Longitud Xs}
		case Xs of _|T then 1 + {Longitud T}
		else 0
		end
   end

   fun {Tomar Xs N}
		if {Longitud Xs} < N then Xs
		else
			case Xs of H|T then
				if N == 0 then nil
				else H|{Tomar T N-1} 
				end
			else 
				nil
			end		
		end
   end

   fun {Eliminar Xs N}
		if N == 0 then Xs
		else 
			case Xs of _|T then
				{Eliminar T N-1}
			else nil
			end				 
		end
   end

   fun {Agregar Xs Ys}
		case Xs of H|T then
			H|{Agregar T Ys}
		else Ys
		end
   end

   fun {Miembro Xs Y}
		case Xs of H|T then
			if H == Y then true
			else {Miembro T Y}
			end
		else false
		end
   end

   fun {Posicion Xs Y}
		case Xs of H|T then
			if H == Y then 1
			else 1 + {Posicion T Y}
			end
		end
   end
end
